package ua.kiev.tosik.price.modules.search.gui.models;

import ua.kiev.tosik.price.models.Prices;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.Vector;

public class TransferablePrices implements Transferable {

	public static DataFlavor pricesFlavor = new DataFlavor(TransferablePricesFlavor.class, "Prices records");
	public static DataFlavor[] supportedFlavors = {pricesFlavor}; //,						// Transfer as a Color object
																  // DataFlavor.stringFlavor,		// Transfer as a String object
																  // DataFlavor.getTextPlainUnicodeFlavor()	// Transfer as a stream of Unicode text

	private TransferablePricesFlavor transferablePricesFlavor;

	public TransferablePrices(Vector<Prices> prices, int[] rows) {
		transferablePricesFlavor = new TransferablePricesFlavor();
		transferablePricesFlavor.setPrices(prices);
		transferablePricesFlavor.setRows(rows);
	}

	@Override
	public DataFlavor[] getTransferDataFlavors() {
		return supportedFlavors;
	}

	@Override
	public boolean isDataFlavorSupported(DataFlavor flavor) {
		return flavor.equals(pricesFlavor);
	}

	@Override
	public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
		if ( flavor.equals(pricesFlavor) ) {
			return transferablePricesFlavor;
		}
		return null;
	}

}